package org.dreamwork.jasmine2.restful.client.gui.ui;

import org.dreamwork.jasmine2.restful.APIDefinition;
import org.dreamwork.secure.SecureContext;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: seth.yang
 * Date: 2014/12/9
 * Time: 2:10
 */
public class APIDescPanel {
    private JPanel root;
    private JLabel txtTitle;
    private JLabel txtDescription;
    private JLabel txtKeyWarp;
    private JLabel txtBlockEncryption;
    private JLabel txtSignature;
    private JButton btnGenerate;

    private Map<String, APIDefinition> map;
    private SecureContext context;

    public APIDescPanel (Map<String, APIDefinition> map, SecureContext context) {
        this.map = map;
        this.context = context;
        guiSetup ();
    }

    public void setTitle (String title) {
        txtTitle.setText (title);
    }

    public void setDescription (String desc) {
        txtDescription.setText (desc);
    }

    public void setKeyWarp (String uri) {
        txtKeyWarp.setText (uri);
    }

    public void setBlockEncryption (String uri) {
        txtBlockEncryption.setText (uri);
    }

    public void setSignature (String uri) {
        txtSignature.setText (uri);
    }

    public JPanel getPanel () {
        return root;
    }

    private void guiSetup () {
        btnGenerate.addActionListener (new ActionListener () {
            @Override
            public void actionPerformed (ActionEvent e) {
                GenerateClassDialog dialog = new GenerateClassDialog (map, context);
                dialog.setSize (500, 360);
                dialog.setResizable (false);
                dialog.setVisible (true);
            }
        });
    }
}
